package com.zfjt.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.OrderNumBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.packnum.PackNum00029;
import com.zfjt.service.OrderNumService;
import com.zfjt.utils.StringUtil;

/**
 * 添加订单序列号(对外不开放)
 * @author xk
 * @version 1.0
 * @date 2017年4月12日
 */
@Controller
public class AddOrdernumController {

	//返回对象
	private ReturnBean mReturn;
		
	private Map<String, String> fhdata;
	
	@Autowired
	private OrderNumService mOrderNum;
	
	@RequestMapping(value="00029")
	@ResponseBody
	public ReturnBean Brabch(HttpSession hseesion){
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00029 num00029 = JSON.parseObject(data,PackNum00029.class); 
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {
			mReturn.setPortnum("00029");
			mReturn.setCode("001");
			fhdata.put("error", "TOKEN_ERROR");
			mReturn.setData(JSON.toJSONString(fhdata));
		}else{
			if (num00029.getPassword().equals("8671598")) {
				for (int i = 0; i < Integer.parseInt(num00029.getNum()); i++) {
					String[] str = StringUtil.convertStrToArray2(UUID.randomUUID().toString());
					mOrderNum.insert(new OrderNumBean(str[4], "", "", num00029.getAccount(), "0", num00029.getDate(), ""));
				}
				mReturn.setPortnum("00029");
				mReturn.setCode("000");
				fhdata.put("chenggong", num00029.getNum());
				mReturn.setData(JSON.toJSONString(fhdata));
			}else {
				mReturn.setPortnum("00029");
				mReturn.setCode("002");
				fhdata.put("error", "PASSWORD_ERROR");
				mReturn.setData(JSON.toJSONString(fhdata));
			}
		}
		return mReturn;
	}
}
